package com.dindang.propertyfee.mvp.ui.adapter.custom;

import android.support.annotation.NonNull;
import android.support.constraint.ConstraintLayout;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dindang.propertyfee.R;
import com.dindang.propertyfee.app.utils.TextViewUtils;
import com.dindang.propertyfee.mvp.model.entity.PropertyCharge;

import java.util.List;

/**物业逾期适配器*/
public class OverdueViewAdapter extends RecyclerView.Adapter<OverdueViewAdapter.ViewHolder> {
    List<PropertyCharge.Recent> list;
    OnClickListener listener;
    public OverdueViewAdapter(List<PropertyCharge.Recent> list, OnClickListener listener) {
        this.list = list;
        this.listener = listener;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.propertyfee_item_overdue, parent, false);
        OverdueViewAdapter.ViewHolder viewHolder = new OverdueViewAdapter.ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        PropertyCharge.Recent recent = list.get(position);
        holder.tv_name.setText(recent.name);
        holder.tv_family.setText(TextViewUtils.getOverdueFamily(recent.total));
        holder.tv_total.setText(TextViewUtils.getAmount(recent.sumAmount));

        holder.ll_expire.setOnClickListener(v -> listener.onClick(position));
    }

    @Override
    public int getItemCount() {
        return list.size();
    }


    class ViewHolder extends RecyclerView.ViewHolder {
        LinearLayout ll_expire;
        TextView tv_name;
        TextView tv_family;
        TextView tv_total;
        ViewHolder(View itemView) {
            super(itemView);
            ll_expire = itemView.findViewById(R.id.propertyfee_ll_expire);
            tv_name = itemView.findViewById(R.id.propertyfee_tv_name);
            tv_family = itemView.findViewById(R.id.propertyfee_tv_family);
            tv_total = itemView.findViewById(R.id.propertyfee_tv_total);
        }
    }

    public interface OnClickListener{
        void onClick(int position);
    }

}